<?php

namespace App\Http\Controllers\Api;

use App\Constants\CollectTypeConstant;
use App\Models\Collect;
use Illuminate\Http\Request;

class MemberCollectController extends Controller
{
    public function list(Request $request)
    {
        $memberId = auth('api')->user()->id ?? 0;

        if (!$memberId) return $this->error('请先登录', [], 40001, 401);

        $list = Collect::with('belong')->where([
            'member_id'   => $memberId,
            'belong_type' => CollectTypeConstant::TYPE_BY_DISEASE_DISCERN
        ])->paginate();

        $list = $list->items();

        return $this->_success(compact('list'));
    }

    public function cancel(int $id)
    {
        $memberId = auth('api')->user()->id ?? 0;

        if (!$memberId) return $this->error('请先登录', [], 40001, 401);

        $info = Collect::where([
            'id'        => $id,
            'member_id' => $memberId,
        ])->first();

        if (!$info) return $this->error('参数错误');

        $info->delete();

        return $this->success('操作成功');
    }
}
